package 结构型设计模式.适配器模式.demo;

// 最后，更新`AudioPlayer`类，使其支持`MediaAdapter`
public class AudioPlayer  implements MediaPlayer{
    MediaAdapter mediaAdapter; // 引用适配器，支持vlc和mp4格式

    @Override
    public void play(String audioType, String fileName) {
        // inbuilt support to play mp3 music files, 原有的mp3功能
        if(audioType.equalsIgnoreCase("mp3")){
            System.out.println("Playing mp3 file. Name: " + fileName);
        }

        // 适配器的引用，支持vlc和mp4格式
        // mediaAdapter is providing support to play other file formats
        else if(audioType.equalsIgnoreCase("vlc") || audioType.equalsIgnoreCase("mp4")){
            mediaAdapter = new MediaAdapter(audioType);
            mediaAdapter.play(audioType, fileName);
        }
        else{
            System.out.println("Invalid media. " + audioType + " format not supported");
        }
    }
}
